﻿namespace ExamV5.LineStudyExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class TaskInfoList : Page
    {
        protected Button butClear;
        protected Button butDefault;
        protected DropDownList DDLDiff;
        protected DropDownList DDLRubricType;
        protected DropDownList DDLStudyType;
        protected DropDownList DDLSubject;
        protected HtmlForm Form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Label labRubricSum;
        protected Label labStudyTip;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        private string string_0 = "0";
        protected TextBox txtUserCode;
        protected TextBox txtUserName;
        protected UpdatePanel UPPart;

        protected void butClear_Click(object sender, EventArgs e)
        {
            string strSql = "delete from StudyHistory  where UserCode='" + this.httpCookie_0.Value + "' and SubjectID=" + this.DDLSubject.SelectedItem.Value;
            this.publicFun_0.ExecuteSql(strSql);
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckB", "alert('清除练习记录操作成功！')", true);
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DDLRubricType_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DDLSubject_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DDLRubricType.Items.Clear();
            this.DDLRubricType.DataTextField = "RubricType";
            this.DDLRubricType.DataValueField = "RubricType";
            this.DDLRubricType.DataSource = this.publicFun_0.RetrunDataView("select  DISTINCT RubricType  from RubricInfo where SubjectID='" + this.DDLSubject.SelectedItem.Value + "' and Flag='B' and RubricType<>'I'  order by RubricType");
            this.DDLRubricType.DataBind();
            if (this.DDLRubricType.Items.Count != 0)
            {
                for (int i = 0; i < this.DDLRubricType.Items.Count; i++)
                {
                    this.DDLRubricType.Items[i].Text = this.publicFun_0.GetRubricType(this.DDLRubricType.Items[i].Value, "0");
                }
            }
            else
            {
                ListItem item = new ListItem("", "0");
                this.DDLRubricType.Items.Add(item);
            }
            this.butClear.Visible = true;
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        private void method_0()
        {
            if (((this.DDLSubject.SelectedItem.Value == "0") || (this.DDLRubricType.SelectedItem.Value == "0")) || (this.DDLRubricType.SelectedItem.Text.Trim() == ""))
            {
                this.labStudyTip.Text = "<font color=red>无</font>";
            }
            else
            {
                string values = this.publicFun_0.GetValues("select Count(*) as CountInfo from RubricInfo where SubjectID='" + this.DDLSubject.SelectedItem.Value + "' and Flag='B' and RubricType='" + this.DDLRubricType.SelectedItem.Value + "'", "CountInfo");
                if (values.Trim() == "")
                {
                    values = "0";
                }
                int num = 0;
                int num2 = 0;
                int num3 = 0;
                int num4 = 0;
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                connection.Open();
                SqlCommand command = new SqlCommand("select * from  StudyHistory where UserCode='" + this.httpCookie_0.Value + "' and SubjectID=" + this.DDLSubject.SelectedItem.Value, connection);
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                if (reader.Read())
                {
                    switch (this.DDLRubricType.SelectedItem.Value)
                    {
                        case "A":
                            if (reader["RubricCountYS"].ToString().Trim() != "")
                            {
                                num2 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountYS"].ToString().Trim() + "0)", "countInfo"));
                            }
                            if (reader["RubricCountNS"].ToString().Trim() != "")
                            {
                                num3 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNS"].ToString().Trim() + "0)", "countInfo"));
                            }
                            num = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNS"].ToString().Trim() + reader["RubricCountYS"].ToString().Trim() + "0)", "countInfo"));
                            num4 = Convert.ToInt32(values) - num;
                            break;

                        case "B":
                            if (reader["RubricCountYD"].ToString().Trim() != "")
                            {
                                num2 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountYD"].ToString().Trim() + "0)", "countInfo"));
                            }
                            if (reader["RubricCountND"].ToString().Trim() != "")
                            {
                                num3 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountND"].ToString().Trim() + "0)", "countInfo"));
                            }
                            num = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountND"].ToString().Trim() + reader["RubricCountYD"].ToString().Trim() + "0)", "countInfo"));
                            num4 = Convert.ToInt32(values) - num;
                            break;

                        case "C":
                            if (reader["RubricCountYB"].ToString().Trim() != "")
                            {
                                num2 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountYB"].ToString().Trim() + "0)", "countInfo"));
                            }
                            if (reader["RubricCountNB"].ToString().Trim() != "")
                            {
                                num3 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNB"].ToString().Trim() + "0)", "countInfo"));
                            }
                            num = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNB"].ToString().Trim() + reader["RubricCountYB"].ToString().Trim() + "0)", "countInfo"));
                            num4 = Convert.ToInt32(values) - num;
                            break;

                        case "D":
                            if (reader["RubricCountYF"].ToString().Trim() != "")
                            {
                                num2 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountYF"].ToString().Trim() + "0)", "countInfo"));
                            }
                            if (reader["RubricCountNF"].ToString().Trim() != "")
                            {
                                num3 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNF"].ToString().Trim() + "0)", "countInfo"));
                            }
                            num = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNF"].ToString().Trim() + reader["RubricCountYF"].ToString().Trim() + "0)", "countInfo"));
                            num4 = Convert.ToInt32(values) - num;
                            break;

                        case "E":
                            if (reader["RubricCountYC"].ToString().Trim() != "")
                            {
                                num2 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountYC"].ToString().Trim() + "0)", "countInfo"));
                            }
                            if (reader["RubricCountNC"].ToString().Trim() != "")
                            {
                                num3 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNC"].ToString().Trim() + "0)", "countInfo"));
                            }
                            num = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNC"].ToString().Trim() + reader["RubricCountYC"].ToString().Trim() + "0)", "countInfo"));
                            num4 = Convert.ToInt32(values) - num;
                            break;

                        case "F":
                            if (reader["RubricCountYA"].ToString().Trim() != "")
                            {
                                num2 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountYA"].ToString().Trim() + "0)", "countInfo"));
                            }
                            if (reader["RubricCountNA"].ToString().Trim() != "")
                            {
                                num3 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNA"].ToString().Trim() + "0)", "countInfo"));
                            }
                            num = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNA"].ToString().Trim() + reader["RubricCountYA"].ToString().Trim() + "0)", "countInfo"));
                            num4 = Convert.ToInt32(values) - num;
                            break;

                        case "G":
                            if (reader["RubricCountYT"].ToString().Trim() != "")
                            {
                                num2 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountYT"].ToString().Trim() + "0)", "countInfo"));
                            }
                            if (reader["RubricCountNT"].ToString().Trim() != "")
                            {
                                num3 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNT"].ToString().Trim() + "0)", "countInfo"));
                            }
                            num = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNT"].ToString().Trim() + reader["RubricCountYT"].ToString().Trim() + "0)", "countInfo"));
                            num4 = Convert.ToInt32(values) - num;
                            break;

                        case "H":
                            if (reader["RubricCountYAn"].ToString().Trim() != "")
                            {
                                num2 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountYAn"].ToString().Trim() + "0)", "countInfo"));
                            }
                            if (reader["RubricCountNAn"].ToString().Trim() != "")
                            {
                                num3 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNAn"].ToString().Trim() + "0)", "countInfo"));
                            }
                            num = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNAn"].ToString().Trim() + reader["RubricCountYAn"].ToString().Trim() + "0)", "countInfo"));
                            num4 = Convert.ToInt32(values) - num;
                            break;

                        case "J":
                            if (reader["RubricCountYJ"].ToString().Trim() != "")
                            {
                                num2 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountYJ"].ToString().Trim() + "0)", "countInfo"));
                            }
                            if (reader["RubricCountNJ"].ToString().Trim() != "")
                            {
                                num3 = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNJ"].ToString().Trim() + "0)", "countInfo"));
                            }
                            num = Convert.ToInt32(this.publicFun_0.GetValues("select  Count(*) as countInfo from RubricInfo where ID in(" + reader["RubricCountNJ"].ToString().Trim() + reader["RubricCountYJ"].ToString().Trim() + "0)", "countInfo"));
                            num4 = Convert.ToInt32(values) - num;
                            break;
                    }
                }
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
                if (num4 < 0)
                {
                    num4 = 0;
                }
                this.labStudyTip.Text = this.DDLSubject.SelectedItem.Text.Replace("│", "").Replace("├", "") + "（" + this.DDLRubricType.SelectedItem.Text + "）共 <font color=red>" + values + "</font> 道,您已答 <font color=red>" + num.ToString() + "</font> 道(答对 <font color=red>" + num2.ToString() + "</font> 道,答错 <font color=red>" + num3.ToString() + "</font> 道)，未答 <font color=red>" + num4.ToString() + "</font> 道";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.string_0 = base.Request["SubjectID"].ToString();
                if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) == 0x3a)
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTHB", "alert('该版本为特惠版，此功能未开放！')", true);
                }
                else if (!base.IsPostBack)
                {
                    if (this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='DayRubric'", "ParmValue").Trim() == "Y")
                    {
                        if (this.publicFun_0.GetValues("select ID from DayRecored where UserCode='" + this.httpCookie_0.Value + "' and Convert(varchar(10),InputTime,120)=Convert(varchar(10),getdate(),120)", "ID") != "")
                        {
                            string str2 = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='ExamWarnShow'", "ParmValue").Trim();
                            if (str2.Trim() == "")
                            {
                                str2 = "Y";
                            }
                            if (!((str2.Trim() == "Y") ? (this.Session["IsShow"] != null) : true))
                            {
                                this.Session["IsShow"] = "Y";
                                base.ClientScript.RegisterClientScriptBlock(this.Page.ClientScript.GetType(), "LoingScript", "ShowWarningInfo();", true);
                            }
                        }
                        else
                        {
                            base.ClientScript.RegisterClientScriptBlock(this.Page.ClientScript.GetType(), "LoingScript", "ShowDayRubricInfo();", true);
                        }
                    }
                    this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "在线练习";
                    this.labStudyTip.Text = "<font color=red>无</font>";
                    this.butClear.Visible = false;
                    this.butClear.Attributes.Add("onclick", "javascript:{if(confirm('确定要清除此科目下的所有练习记录吗？')==false) return false;}");
                    if (this.publicFun_0.ReturnPaperData() != "Yes")
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请与管理员联系！')", true);
                    }
                    else
                    {
                        string str = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='StudyRubricSum'", "ParmValue").Trim();
                        if (str.Trim() == "")
                        {
                            this.labRubricSum.Text = "10";
                        }
                        else
                        {
                            this.labRubricSum.Text = str;
                        }
                        this.txtUserCode.Text = this.httpCookie_0.Value;
                        this.txtUserName.Text = this.httpCookie_1.Value;
                        this.DDLRubricType.Items.Clear();
                        this.publicFun_0.LoadSubjectInfo(this.DDLSubject, this.httpCookie_0.Value, "N", "B", this.httpCookie_3.Value);
                        this.DDLSubject.Items.Insert(0, new ListItem("--请选择练习科目--", "0"));
                        try
                        {
                            this.DDLSubject.Items.FindByValue(this.string_0).Selected = true;
                            this.DDLRubricType.Items.Clear();
                            this.DDLRubricType.DataTextField = "RubricType";
                            this.DDLRubricType.DataValueField = "RubricType";
                            this.DDLRubricType.DataSource = this.publicFun_0.RetrunDataView("select  DISTINCT RubricType  from RubricInfo where SubjectID='" + this.DDLSubject.SelectedItem.Value + "' and Flag='B' and RubricType<>'I'  order by RubricType");
                            this.DDLRubricType.DataBind();
                            if (this.DDLRubricType.Items.Count != 0)
                            {
                                for (int i = 0; i < this.DDLRubricType.Items.Count; i++)
                                {
                                    this.DDLRubricType.Items[i].Text = this.publicFun_0.GetRubricType(this.DDLRubricType.Items[i].Value, "0");
                                }
                            }
                            else
                            {
                                ListItem item = new ListItem("", "0");
                                this.DDLRubricType.Items.Add(item);
                            }
                            this.butClear.Visible = true;
                            this.method_0();
                        }
                        catch
                        {
                        }
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

